package financial

import (
	"github.com/beego/beego/v2/client/orm"
	"ltbz/cultural_tourism_api/utils"
)

//合作景区

type CooperateScenicSpot struct {
}

// 合作景区-财务数据
type CooperateScenicSpotFinancialData struct {
	CurrentDayOutTicket   int `description:"当日出票数量"`
	CurrentWeekOutTicket  int `description:"当周出票数量"`
	CurrentMonthOutTicket int `description:"当月出票数量"`
	Total                 int `description:"累计出票数量"`
}

type CooperateScenicSpotOrderListReq struct {
	TradeCode   string `description:"订单编码"`
	UserCode    string `description:"用户ID"`
	Mobile      string `description:"手机号"`
	StartTime   string `description:"开始时间"`
	EndTime     string `description:"结束时间"`
	TradeStatus string `description:"订单状态:'待支付','支付中','支付失败','待使用','已使用','退款中','退款成功','退款失败','已生效','已取消'"`
	utils.PagingReq
}

func (r *CooperateScenicSpot) GetCooperateScenicSpotOrderPageCount(condition string, pars []interface{}) (count int, err error) {
	o := orm.NewOrm()
	sql := `SELECT COUNT(1) AS count FROM trade WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	err = o.Raw(sql, pars).QueryRow(&count)
	return
}

func (r *CooperateScenicSpot) GetCooperateScenicSpotOrderPage(condition string, pars []interface{}, startSize, pageSize int) (items []*ImperialPalaceOrderView, err error) {
	o := orm.NewOrm()
	sql := `SELECT a.* FROM trade AS a  WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}

type CooperateScenicSpotOrderListPageResp struct {
	List   []*ImperialPalaceOrderView
	Paging *utils.PagingResp
}

func (r *CooperateScenicSpot) GetCooperateScenicSpotTicket(condition string, pars []interface{}) (total int, err error) {
	o := orm.NewOrm()
	sql := ` SELECT COUNT(1) AS total FROM trade AS a
			INNER JOIN trade_order AS b ON a.trade_id=b.trade_id
			INNER JOIN goods_product AS c ON b.goods_product_id=c.goods_product_id
			WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	err = o.Raw(sql, pars).QueryRow(&total)
	return
}

type CooperateScenicSpotOrderListExportReq struct {
	TradeCode   string `description:"订单编码"`
	UserCode    string `description:"用户ID"`
	Mobile      string `description:"手机号"`
	StartTime   string `description:"开始时间"`
	EndTime     string `description:"结束时间"`
	TradeStatus string `description:"订单状态:'待支付','支付中','支付失败','待使用','已使用','退款中','退款成功','退款失败','已生效','已取消'"`
}

func (r *CooperateScenicSpot) GetCooperateScenicSpotOrderExport(condition string, pars []interface{}) (items []*ImperialPalaceOrderView, err error) {
	o := orm.NewOrm()
	sql := `SELECT a.* FROM trade AS a  WHERE 1=1 `
	if condition != "" {
		sql += condition
	}
	sql += ` ORDER BY a.create_time DESC `
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}
